# 测试用户权限API
$baseUrl = "http://localhost:5000"

Write-Host "=== 测试用户权限API ===" -ForegroundColor Green

# 1. 测试获取用户个人信息（包含角色和权限）
Write-Host "`n1. 测试获取用户个人信息..." -ForegroundColor Yellow
$userId = "44444444-4444-4444-4444-444444444444"  # admin用户ID
$response = Invoke-RestMethod -Uri "$baseUrl/api/user/profile" -Method Get -ContentType "application/json"

Write-Host "响应状态: $($response.success)"
if ($response.success) {
    Write-Host "用户信息: $($response.data.username)"
    Write-Host "角色数量: $($response.data.roles.Count)"
    Write-Host "权限数量: $($response.data.permissions.Count)"
    
    if ($response.data.roles.Count -gt 0) {
        Write-Host "角色列表:"
        foreach ($role in $response.data.roles) {
            Write-Host "  - $($role.name): $($role.description)"
        }
    }
    
    if ($response.data.permissions.Count -gt 0) {
        Write-Host "权限列表:"
        foreach ($permission in $response.data.permissions) {
            Write-Host "  - $permission"
        }
    }
} else {
    Write-Host "错误: $($response.message)" -ForegroundColor Red
}

# 2. 测试获取用户权限API
Write-Host "`n2. 测试获取用户权限API..." -ForegroundColor Yellow
$permissionRequest = @{
    userId = $userId
} | ConvertTo-Json

$response = Invoke-RestMethod -Uri "$baseUrl/api/permission/user-permissions" -Method Post -Body $permissionRequest -ContentType "application/json"

Write-Host "响应状态: $($response.success)"
if ($response.success) {
    Write-Host "用户: $($response.data.username)"
    Write-Host "角色数量: $($response.data.roles.Count)"
    Write-Host "权限数量: $($response.data.permissions.Count)"
    Write-Host "菜单数量: $($response.data.menus.Count)"
} else {
    Write-Host "错误: $($response.message)" -ForegroundColor Red
}

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green 